<template>
  <div id="crowdDictionary">
    <!--上部搜索条件-->
    <topSearch :form-inline="formInline" @toSearch="toSearch"></topSearch>
    <div class="table-conBtn">
      <freshCom @searchList="getRules"></freshCom>
    </div>

    <!--底部表格部分-->
    <el-table
      v-loading="loading"
      :data="tableData"
      style="width: 100%"
      max-height="490"
      ref="table"
    >
      <el-table-column type="index" width="100" align="center" label="序号">
        <template slot-scope="scope">
          {{
            scope.$index
              | filterPage(searchParams.pageNum, searchParams.pageSize)
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="规则名称"
        prop="name"
        min-width="120"
        align="center"
      ></el-table-column>
      <el-table-column
        label="值类型"
        prop="inputDesc"
        min-width="150"
        align="center"
      ></el-table-column>
      <el-table-column
        label="备注说明"
        prop="remark"
        min-width="120"
        align="center"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.remark">{{ scope.row.remark }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="分类" prop="type" min-width="120" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.type === 'ACTION'">行为类别</span>
          <span v-else-if="scope.row.type === 'IDENTITY'">身份类别</span>
          <span v-else-if="scope.row.type === 'OPERATION'">运营类别</span>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-全局组件-->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="getRules"
    ></pageCom>
  </div>
</template>

<script>
import topSearch from '@component/userManagement/crowdManage/topDictionarySearch' // 上部搜索条件
import { getPeopleRuleDic } from '@/api/userManagement/userManageAPI'
export default {
  name: 'crowdDictionary',
  msg: '人群管理/创建人群/字典',
  components: {
    topSearch
  },
  data() {
    return {
      formInline: {
        name: ''
      },
      tableData: [],
      loading: false,
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      total: 0
    }
  },
  mounted() {
    this.getRules()
  },
  methods: {
    getRules() {
      this.loading = true
      let params = { ...this.searchParams, ...this.formInline }
      getPeopleRuleDic(
        params,
        (response) => {
          this.total = response.total
          this.tableData = response.rows
          this.loading = false
        },
        (response) => {
          this.loading = false
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    // 改变页码
    changePage(page) {
      this.searchParams.pageNum = page
      this.getRules()
    },
    // 搜索
    toSearch() {
      this.searchParams.pageNum = 1
      this.getRules()
    }
  }
}
</script>

<style lang="less"></style>
